<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div{
            width: 120px;
            height: 120px;
            background-color: black;
        }
        header{
            width: 500px;
            height: 200px;
            display: flex;
            justify-content: space-around;
        }
    </style>
</head>

<body>
    <button onclick="btn()">点击将DIV变为红色</button>
   <header>
    <div>

    </div>
    <div>

    </div>
    <div>

    </div>
   </header>
</body>

</html>
<script>
    let div=document.querySelectorAll('div')
    function btn(){
        for(let i=0;i<div.length;i++){
            console.log(div.length);
            div[i].style.background='red'
        }
    }
</script>